#include<iostream>
#include<string.h>
#include<queue>
#include<map>
using namespace std;
bool M[1005][1005],vis[1005][1005];
int F[1005][1005],N,bx,by;
const int X[]={1,-1,0,0};
const int Y[]={0,0,-1,1};
void bfs(){
	memset(F,0x3f,sizeof F);
	F[bx][by]=0;
	vis[bx][by]=1;
	deque<pair<int,int> >q;
	q.push_back(make_pair(bx,by));
	while(q.size()){
		int x=q.front().first,y=q.front().second;
		q.pop_front();
		if(x==0 && y==0){
			cout<<F[x][y];
			return;
		}
		for(int i=0;i<4;i++){
			int nxx=x+X[i],nxy=y+Y[i];
			if(nxx<0||nxx>1001||nxy<0||nxy>1001||vis[nxx][nxy])continue;
			vis[nxx][nxy]=1;
			F[nxx][nxy]=F[x][y]+M[nxx][nxy];
			if(M[nxx][nxy])q.push_back(make_pair(nxx,nxy));
			else q.push_front(make_pair(nxx,nxy));
		}
	}
}
int main(){
	cin>>N>>bx>>by;
	for(int i=1,x,y;i<=N;i++){
		cin>>x>>y;
		M[x][y]=1;
	}
	bfs();
}
